package Chapter6;

public class BinaryNode<T> {
    public T data;
    public BinaryNode<T> left, right;

    public BinaryNode(T data, BinaryNode<T> left, BinaryNode<T> right) {
        this.data = data;
        this.left = left;
        this.right = right;
    }

    public BinaryNode(T data) {
        this(data, null, null);
    }

    public BinaryNode(){
        this(null,null,null);
    }

    public String toString() {
        return this.data.toString();
    }

    public boolean isLeaf() {
        return this.left == null && this.right == null;
    }

    public boolean equals(Object obj) {
        if (obj == this)
            return true;
        if (obj instanceof BinaryNode<?>) {
            return this.data.equals(((BinaryNode<T>) obj).data);
        }
        return false;
    }
}
